/*
 * @lc app=leetcode.cn id=2309 lang=typescript
 *
 * [2309] 兼具大小写的最好英文字母
 */

// @lc code=start
function greatestLetter(s: string): string {
    const cache = new Array(26).fill(0);
    const cache_0 = new Array(26).fill(0);
    for (let i = 0; i < s.length; i++) {
        const code = s.charCodeAt(i);
        if (code < 95) {
            cache_0[code - 65]++;
        } else {
            cache[code - 97]++;
        }
    }
    for (let i = 25; i >= 0; i--) {
        if (cache[i] && cache_0[i]) return String.fromCharCode(65 + i);
    }
    return "";
}
// @lc code=end
